package com.grasscove.namethat.adapters;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.grasscove.namethat.R;
import com.grasscove.namethat.SettingsList;

public class SettingsListAdapter extends BaseAdapter
{
	private Context mContext;
	private SharedPreferences mSettings;

	private TextView mSettingsTitle;
	private TextView mSettingsDesc;
	private TextView mCountdownText;

	private CheckBox mCheckbox;

	public SettingsListAdapter(Context context, SharedPreferences settings) {
		mContext = context;
		mSettings = settings;
	}

	@Override
	public int getCount() {
		//return 4;
		return 1; //return 1 here to only display the first row
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout row;

		if (convertView == null) {
			row = new LinearLayout(mContext);

			LayoutInflater vi;
			vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			if (position == 0) {
				vi.inflate(R.layout.settings_countdown_row, row, true);
			} else {
				vi.inflate(R.layout.settings_row, row, true);
			}
		} else {
			row = (LinearLayout) convertView;
		}

		mSettingsTitle = (TextView) row.findViewById(R.id.settings_row_title);
		mCheckbox = (CheckBox) row.findViewById(R.id.settings_row_checkbox);

		switch (position) {
			case 0:
				mCountdownText = (TextView) row.findViewById(R.id.settings_countdown_text);
				mCountdownText.setText(SettingsList.COUNTDOWN_MINUTES[mSettings.getInt("countdown_time", 0)]);
				break;
			case 1:
				mSettingsTitle.setText("Start Game Immediatly");
				mSettingsDesc = (TextView) row.findViewById(R.id.settings_row_desc);
				mSettingsDesc.setText("Start the game as soon as you select a category.");
				mCheckbox.setChecked(mSettings.getBoolean("start_immediatly", false));
				break;
			case 2:
				mSettingsTitle.setText("Startup Window");
				mCheckbox.setChecked(mSettings.getBoolean("startup_window", false));
				break;
			case 3:
				mSettingsTitle.setText("Auto Switch Team");
				mSettingsDesc = (TextView) row.findViewById(R.id.settings_row_desc);
				mSettingsDesc.setText("Switch currently active team after each new word.");
				mCheckbox.setChecked(mSettings.getBoolean("auto_team_switch", false));
				break;
		}

		return row;
	}
}